package com.study.algorithm.base.list;

import com.study.algorithm.base.common.ListUtil;
import org.apache.commons.lang3.RandomUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * ChooseSort
 *
 * @author wanghuilong
 * @version 1.0
 * @description choose sort
 * @date 2022/10/26 17:05
 */
public class ChooseSort {


    public static void main(String[] args) {

        List<Integer> list = ListUtil.getRandomList(10);
        System.out.println(list);
        chooseSort(list);
    }

    /**
     *
     * @param list
     * @return
     */
    public static void chooseSort(List<Integer> list) {
        for (int i = 0; i < list.size() - 1 ; i++) {
            int k = i;
            for (int j = i + 1; j < list.size(); j++) {
                if(list.get(j) < list.get(k)) {
                    k = j;
                }
            }
            if(k != i) {
                ListUtil.swap(list,i,k);
            }
        }
        System.out.println(list);
    }





}
